import matplotlib.pyplot as plt

# 设置中文字体和其他全局属性
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.rcParams['figure.dpi'] = 100
plt.rcParams['figure.figsize'] = (10, 6)

# 创建图形
fig, ax = plt.subplots()

# 数据
months = ['1月', '2月', '3月', '4月', '5月', '6月']
sales_2021 = [1385, 1846, 1345, 1654, 1936, 1936]
sales_2022 = [1686, 1934, 1658, 2564, 2236, 1865]

# 配置背景颜色
fig.patch.set_facecolor('#1b1d4e')
ax.set_facecolor('#1b1d4e')

# 绘制折线图
ax.plot(months, sales_2021, marker='o', color='#ef6174', label='2021年')
ax.plot(months, sales_2022, marker='o', color='#5383ff', label='2022年')

# 设置坐标轴
ax.set_yticks([0, 500, 1000, 1500, 2000, 2500, 3000])
ax.tick_params(axis='y', colors='white')
ax.set_xticks(range(len(months)))
ax.set_xticklabels(months, color='white')
ax.set_ylim(0, 3000)

# 添加网格
ax.grid(color='white', linestyle='--', linewidth=0.5, alpha=0.5)
# 添加标题
plt.title('2022年上半年各月同比去年销量', fontsize=30, weight='bold', loc='left', pad=25, color='white')
# 添加子标题
plt.text(0.5, 1.03, '上半年同比去年增长明显，5月份同比增长最多，增长近40%', ha='center', va='center',
         transform=plt.gca().transAxes, fontsize=20, color='white')
# 设置图例
ax.legend(fontsize=12, loc='upper right')
ax.xaxis.grid(False)
ax.spines['bottom'].set_color('#5D607A')

# 去掉边框
for spine in ax.spines.values():
    spine.set_edgecolor('#1b1d4e')

# 显示图形
plt.show()
